﻿using System;
using System.Reflection;
using System.Configuration;
using Slc.Core.Enums;
using System.Web.Configuration;

namespace Slc.Core.Config
{
    public static class GlobalConfig
    {

        #region Static Methods
        /// <summary>
        /// Runtime Section
        /// </summary>
        private static ConfigSection section
        {
            get
            {
                return ConfigurationManager.GetSection(ConfigSectionName.Slc) as ConfigSection;
            }
        }
        /// <summary>
        /// Gets 产品名称
        /// </summary>
        public static string ProductName
        {
            get
            {
                return ConfigSectionName.Slc;
            }
        }

        /// <summary>
        ///Gets 当前版本
        /// </summary>
        public static string ProductVersion
        {
            get
            {
                Version v = Assembly.GetExecutingAssembly().GetName().Version;
                string vStr = String.Format("{0}.{1}.{2}", v.Major, v.Minor, v.Build);
                if (v.Revision != 0)
                {
                    vStr = String.Format("{0}.{1}", vStr, v.Revision);
                }

                return vStr;
            }
        }


        /// <summary>
        /// Gets语言
        /// </summary>
        public static Language GetLanguage()
        {
            return (Language)Enum.Parse(typeof(Language), section.Language, true);
        }

        /// <summary>
        /// Gets数据库类型
        /// </summary>
        public static DataDbType GetDataDbType()
        {
            return (DataDbType)Enum.Parse(typeof(DataDbType), section.DataDbType, true);
        }
        /// <summary>
        /// Gets日志文件
        /// </summary>
        public static string GetLogPath()
        {
            return section.LogPath;
        }
        /// <summary>
        /// Gets数据库连接
        /// </summary>
        public static string GetConnectionString()
        {
            return section.ConnectionString;
        }
        /// <summary>
        /// Gets数据库版本
        /// </summary>
        public static DbVersion GetDbVersion()
        {
            switch (section.DbVersion.ToUpper())
            {
                case "SQL2000":
                    return DbVersion.MSSQL2000;
                case "SQL2005":
                    return DbVersion.MSSQL2005;
                case "SQL2008":
                    return DbVersion.MSSQL2008;
                default:
                    return DbVersion.MSSQL2008;
            }
        }
        /// <summary>
        /// Gets数据库操作实例程序集
        /// </summary>
        public static string GetHelperAssembly()
        {
            return section.HelperAssembly;
        }

        /// <summary>
        /// Gets指定数据库操作类
        /// </summary>
        public static string GetHelperType()
        {
            return section.HelperType;
        }
        /// <summary>
        ///Gets DEBUG 模式
        /// </summary>
        public static bool GetDebugMode()
        {
            return Convert.ToBoolean(section.DebugMode);
        }
        /// <summary>
        /// Gets 是否启用日志
        /// </summary>
        public static bool GetEnabledLog()
        {
            return Convert.ToBoolean(section.EnabledLog);
        }
        /// <summary>
        ///Gets 日志执行时间设置
        /// </summary>
        public static long GetLogExeTime()
        {
            return Convert.ToInt64(section.LogExeTime);
        }
        #endregion

    }
}
